import numpy as np
import matplotlib.pyplot as plt
from math import ceil, floor, sqrt
from matplotlib import gridspec
from matplotlib import rcParams
rcParams['font.family'] = 'times new roman'
rcParams['font.size'] = 15
rcParams['font.weight'] = 'normal'


# topology
numToRs     = 16
numHosts    = 4
numLinks    = 4
numSLinks   = 2

# workloads
flowsDir = '1/'
load = 0.4
time = 0.4
workloadCDFs  = ['DCTCP']
workloadTypes = ['permutation']

# scheduler
scheduler = ['Detour','OvS']#, 
iteration_a = 0
iteration_b = 1

interval = 5

x_osa=[]
y_osa=[]
x_ovs=[]
y_ovs=[]
x_detour=[]
y_detour=[]
counter = 0
for i in xrange(iteration_a, iteration_b):
    for workloadType in workloadTypes:
        for workloadCDF in workloadCDFs:
            for sched in scheduler:
                flowsFileName = "%s_%sToR_%sHosts_%sLinks_%sload_%stime_%s_%s_%s_sample.txt" \
                            %(sched, numToRs, numHosts, numLinks, load, time, workloadType, workloadCDF, i)

                with open( flowsFileName, 'r') as f:
                    for line in f.readlines():
                    	split = line.split()
                        counter += 1
                    	if len(split)==4 and counter == interval:
                            counter = 0
                            if sched == "Detour":
                                x_detour.append(float(split[1]))
                                y_detour.append(float(split[-1]))
                            if sched == "OvS":
                                x_ovs.append(float(split[1]))
                                y_ovs.append(float(split[-1]))
                            if sched == "OSA":
                                x_osa.append(float(split[1]))
                                y_osa.append(float(split[-1]))

lw = 0.9
ms = 6
fig = plt.figure(figsize=(5.8,3.5))
ax = plt.axes()
plt.plot(x_osa,y_osa, 'r')
plt.plot(x_ovs,y_ovs, color= 'b', ls='-', lw=lw, ms=ms, zorder=3)
plt.plot(x_detour,y_detour, color= 'y', ls='-', lw=lw, ms=ms, zorder=3)
#plt.xlim(0, 0.2)
plt.xlabel('Time (s)')
plt.ylabel('Network Thoughput (bps)')
plt.subplots_adjust(bottom=0.15, top=0.92, left=0.1, right=0.95)
ax.yaxis.grid(zorder=0, ls='--')
#plt.savefig('0_Simulation_FCT.pdf')
plt.show()